from collections import Counter

#读取频率最高的词
def count_most_common_words(word_list, nums):
    counter = Counter(word_list)
    total = sum(counter.values())
    for word, count in counter.most_common(nums):
        print(word, count, f'--{count/total:.2%}')

keywords = ['购物', '促销', '降价', '美食', '运动', '科技', '手机', '天气', '数码', '芯片', '内存', '硬盘']
for keyword in keywords:
    print(f'"{keyword}"的中介关键词词频统计')
    with open(f"data/segmentation/{keyword}_segmentation_clean_remove_stop_words.csv", 'r', encoding='utf-8') as source_file:
        word_list = source_file.read().splitlines()
        count_most_common_words(word_list, 10)
